<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件，不影响升级覆盖
 */

class Dianzan extends \Phpcmf\Home\Module
{

	public function  dianzan_panduan() {
		//get 参数
		if(!$this->uid){
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$dianzan_tongji = \Phpcmf\Service::M()->db->table('1_zhishi_form_kecheng_dianzan')->where('tieid', $id)->countAllResults();
			$data = [
				'code' => 0,
				'data' => $dianzan_tongji,
				'uid'=> 0,

			];
			$this->_json('1', '未登录',$data);									
		} else {
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
			$dianzan_data = \Phpcmf\Service::M()->db->table('1_zhishi_form_kecheng_dianzan')->where('tieid', $id)->where('uid', $this->uid)->countAllResults();
			$dianzan_tongji = \Phpcmf\Service::M()->db->table('1_zhishi_form_kecheng_dianzan')->where('tieid', $id)->countAllResults();
			if($dianzan_data){
				$data = [
					'code' => 1,
					'data' => $dianzan_tongji,
					'uid'=> $this->uid,
	
				];
	
				$this->_json('1', '已点赞',$data);
			} else {
				$data = [
					'code' => 2,
					'data' => $dianzan_tongji,
					'uid'=> $this->uid,
	
				];

				$this->_json('0', '未点赞',$data);
			}
		}
		
		
	}
	// 头像
	public function  dianzan_touxiang() {
		$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
		$shuju_data = \Phpcmf\Service::M()->table('1_zhishi_form_kecheng_dianzan')->where('tieid', $id)->getAll();
		// 循环头像
		$touxiang = [];
		if($shuju_data){
			foreach ($shuju_data as $key => $value) {
				$touxiang[] = dr_avatar($shuju_data['uid']);
			}
		}

		$this->_json('0', '点赞头像',$touxiang);
		
	}

}
